<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page import="com.park.layout.Blocks" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%-- JSTL表达式（判断，循环，输出） --%>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> <%-- 方法表达式（字符串截取，替换） --%>
<%@ taglib uri="http://www.wanwei.com/tags/tag" prefix="layout" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>


<layout:override name="<%=Blocks.BLOCK_HEADER_CSS%>">
    <link href="Content/style/common/style.min.css?v=${static_resource_version}" rel="stylesheet" type="text/css">
    <style>
        .banner{    border: 1px solid #E5E5E5; padding: 20px;}
    </style>
</layout:override>

<layout:override name="<%=Blocks.BLOCK_HEADER_SCRIPTS%>">
    <script src="Content/dist/jquery-form.js?v=${static_resource_version}"></script>
    <script>
        $(document).ready(function () {
            <c:if test="${fn:length(subordinate.firstLevel) == 0}">
                addBanner();
            </c:if>
        });

        function addBanner() {
            $.ajax({
                url: "<%=basePath%>member/getUserOperatorListByFenxiao",
                data: {uid: '${member.id}'},
                async: false,
                success: function (data) {
                    $("#banners").append(data);
                }
            });
        }

        function updateBanner(obj){
            var form =  $($(obj).closest("form"));
            if(!form.find(".subUser").val()){
                alert("请选择下级用户");
                return;
            }
            $(obj).prop("disabled", true);
            form.ajaxSubmit({
                type: "post",
                dataType: "json",
                data: form.serialize(),
                url: "<%=basePath%>member/updateUserFenxiao",
                success: function (res) {
                    alert(res.message);
                    if(res.code == 1) {
                        window.location.reload();
                    }
                    $(obj).prop("disabled", false);
                },
                error: function (msg) {}
            });
        }

        function deleteBanner(subUid, obj){
            if(window.confirm("确认删除下级用户吗？")) {
                $.post("<%=basePath%>member/deleteUserFenxiao", {uid: '${member.id}', subUid: subUid}, function (res) {
                    if (res.code == 1) {
                        window.location.reload();
                    } else {
                        alert(res.message);
                    }
                });
            }
        }

        function updateCommission(){
            if(window.confirm("确认修改此用户的奖金吗？")) {
                $.post("<%=basePath%>member/newCommission", {uid: '${member.id}', commission: $("#commission").val()}, function (res) {
                    alert(res.message);
                    if (res.code == 1) {
                        window.location.reload();
                    }
                });
            }
        }
    </script>
</layout:override>

<layout:override name="<%=Blocks.BLOCK_BODY%>">
    <div class="container-fluid" style="text-align: left">
        <div id="center_form" class="form-horizontal" novalidate>
            <div class="panel panel-default">
                <div class="panel-heading">用户管理</div>
                <div class="panel-body">

                    <div class="col-sm-6">
                        <div class="form-group">
                            <label class="col-sm-4 control-label">
                                用户昵称
                            </label>

                            <div class="col-sm-8">
                                <input type="text" class="form-control" value="${member.operatorName}" disabled readonly>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-4 control-label">
                                一级下级人数
                            </label>

                            <div class="col-sm-8">
                                <input type="text" class="form-control" value="${fn:length(subordinate.firstLevel)}个 <c:if test="${fn:length(subordinate.firstLevel)>0}">(<c:forEach var="first" items="${subordinate.firstLevel}" varStatus="s"><c:if test="${s.index > 0}">，</c:if>${first.operatorName}</c:forEach>)</c:if>" disabled readonly>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-4 control-label">
                                二级下级人数
                            </label>

                            <div class="col-sm-8">
                                <input type="text" class="form-control" value="${fn:length(subordinate.secondLevel)}个 <c:if test="${fn:length(subordinate.secondLevel)>0}">(<c:forEach var="second" items="${subordinate.secondLevel}" varStatus="s"><c:if test="${s.index > 0}">，</c:if>${second.operatorName}</c:forEach>)</c:if>" disabled readonly>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-4 control-label">
                                三级下级人数
                            </label>

                            <div class="col-sm-8">
                                <input type="text" class="form-control" value="${fn:length(subordinate.thirdLevel)}个 <c:if test="${fn:length(subordinate.thirdLevel)>0}">(<c:forEach var="third" items="${subordinate.thirdLevel}" varStatus="s"><c:if test="${s.index > 0}">，</c:if>${third.operatorName}</c:forEach>)</c:if>" disabled readonly>
                            </div>
                        </div>

                    </div>

                <div class="col-sm-6">

                    <div class="form-group">
                        <label class="col-sm-4 control-label">
                            手机号码
                        </label>

                        <div class="col-sm-8">
                            <input type="text" class="form-control" value="${member.operatorMobile}" disabled readonly>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">
                            用户状态
                        </label>

                        <div class="col-sm-8">
                            <input type="text" class="form-control" value="<c:choose><c:when test="${member.status == 1}">正常</c:when><c:otherwise> 锁定 </c:otherwise></c:choose>" disabled readonly>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">
                            功德值
                        </label>

                        <div class="col-sm-8">
                            <input type="text" class="form-control" value="${member.meritPoint}" disabled readonly>
                        </div>
                    </div>
                </div>

                <div class="col-sm-6">

                    <div class="form-group">
                        <label class="col-sm-4 control-label">
                            用户奖金
                        </label>

                        <div class="col-sm-6">
                            <input type="text" id="commission" class="form-control" value="${member.commission}" placeholder="请输入用户奖金(数字)">
                        </div>
                        <div class="col-sm-2">
                            <button type="button" style="border: none; padding: 6px;" onclick="updateCommission()">修改用户奖金</button>
                        </div>
                    </div>

                </div>

                    <div class="col-sm-offset-2 col-sm-8" style="padding-bottom: 200px;">
                        <div id="banners">

                            <c:forEach var="s" items="${subordinate.firstLevel}">
                            <div class="banner">
                            <form enctype="multipart/form-data">
                                <input type="hidden" name="uid" value="${member.id}" />
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">
                                        选择下级一级用户
                                    </label>

                                    <div class="col-sm-8">
                                        <select class="form-control subUser" name="subUid" style="height: auto;" disabled>
                                            <c:forEach var="u" items="${userOperatorList}">
                                                <option value="${user.id}" <c:if test="${s.id==u.id}">selected</c:if>>${u.operatorName} (${u.operatorMobile})</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="text-center" style="padding-top: 20px;">
                                        <button type="button" class="btn" style="width: 100px; margin-left: 30px;" onclick="deleteBanner('${s.id}', this)">
                                            <span class="glyphicon"></span> 删除
                                        </button>
                                    </div>
                                </div>
                            </form>
                            </div>
                            </c:forEach>

                        </div>

                        <div class="form-group">
                            <div class="text-center" style="padding-top: 50px;">
                                <button type="button" class="btn" style="width: 150px; margin-left: 30px; background-color: wheat;" onclick="addBanner()">
                                    <span class="glyphicon"></span> 增加下级用户
                                </button>
                                <button type="button" class="btn col-sm-4" style="width: 150px; float: right;" onclick="window.history.go(-1);">
                                    <span class="glyphicon"></span> 返回
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</layout:override>

<c:import url="../Shared/Layout.jsp">
    <c:param name="title" value=""/>
</c:import>
